//
//  WQTabBarController.m
//  sanwuWeiboOC
//
//  Created by 王先强 on 15/12/6.
//  Copyright © 2015年 王先强. All rights reserved.
//

#import "WQTabBarController.h"
#import "WQHomeController.h"
#import "WQMessageController.h"
#import "WQDiscoverController.h"
#import "WQProfileController.h"
#import "UIButton+WQExtension.h"
@interface WQTabBarController ()

@property (nonatomic, weak) UIButton *composeBtn;

@end

@implementation WQTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupTabBar];
    [self setupComposeBtn];
 
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSInteger count = self.childViewControllers.count;
    CGFloat width = self.tabBar.bounds.size.width / count - 2;
    self.composeBtn.frame = CGRectInset(self.tabBar.bounds, 2 * width, 0);
    [self.tabBar bringSubviewToFront:self.composeBtn];
}

-(void)setupComposeBtn{
    UIButton *composeBtn = [UIButton buttonWithImageName:@"tabbar_compose_icon_add" backgroundImageName:@"tabbar_compose_button"];
    self.composeBtn = composeBtn;
    [self.tabBar addSubview:composeBtn];
}

-(void)setupTabBar
{
    self.tabBar.tintColor = [UIColor orangeColor];
    [self addControllerWithController:[[WQHomeController alloc] init] imageName:@"tabbar_home" title:@"主页"];
    [self addControllerWithController:[[WQMessageController alloc] init] imageName:@"tabbar_message_center" title:@"消息"];
    [self addChildViewController:[[UIViewController alloc] init]];
    [self addControllerWithController:[[WQDiscoverController alloc] init] imageName:@"tabbar_discover" title:@"发现"];
    [self addControllerWithController:[[WQProfileController alloc] init] imageName:@"tabbar_profile" title:@"我"];
}

-(void)addControllerWithController:(UIViewController *)vc imageName:(NSString *)imageName title:(NSString *)title
{
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    vc.title = title;
    [vc.tabBarItem setImage:[UIImage imageNamed:imageName]];
    [self addChildViewController:nav];
}



@end
